import { SOfficerInfo } from "../../../../Message/Game/SOfficerInfo";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { ECountryPositionOperType } from "../../../../Message/Game/ECountryPositionOperType";
import { ECountryPosition } from "../../../../Message/Game/ECountryPosition";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { _position } from "../../../../this/_position";
import { _posName } from "../../../../this/_posName";
type int = number;
//class CountryPivillageOperPanel
    
    export  class CountryPivillageOperPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public set position(arg1: int)
        {
            this._position = arg1;
            return;
        }

        public set officerInfo(arg1: SOfficerInfo)
        {
            this._officerInfo = arg1;
            return;
        }

        public set playerName(arg1: string)
        {
            this._playerName = arg1;
            return;
        }

        public set posName(arg1: string)
        {
            this._posName = arg1;
            return;
        }

        public get privillageNum(): int
        {
            return this._privillageNum;
        }

        /* internal  */init(): void
        {
            this._panelBg = ObjCreate.createBg(0, 0, 80, 20, this, ImagesConst.ToolTipBg);
            return;
        }

        public addPrivilegeOper(arg1: string): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case "resign":
                {
                    if (this._resignTxt == null) 
                    {
                        this._resignTxt = ObjCreate.createGTextField("", this._btnX, this._btnY, 80, 20, this, GlobalStyle.textFormatGreen);
                        this._resignTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(36439) + "</u></a>";
                        this._resignTxt.addEventListener(flash.events.TextEvent.LINK, this.onResignTxtLinkHandler);
                        this._btnY = this._btnY + 25;
                    }
                    addChild(this._resignTxt);
                    this._privillageNum = this._privillageNum + 1;
                    break;
                }
                case "positionOper":
                {
                    if (this._positionOperTxt == null) 
                    {
                        this._positionOperTxt = ObjCreate.createGTextField("", this._btnX, this._btnY, 80, 20, this, GlobalStyle.textFormatGreen);
                        this._positionOperTxt.addEventListener(flash.events.TextEvent.LINK, this.onPositionOperTxtLinkHandler);
                        this._btnY = this._btnY + 25;
                    }
                    if (this._officerInfo) 
                    {
                        this._positionOperTxt.name = "recall";
                        this._positionOperTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(36441) + "</u></a>";
                    }
                    else 
                    {
                        this._positionOperTxt.name = "appoint";
                        this._positionOperTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(36440) + "</u></a>";
                    }
                    addChild(this._positionOperTxt);
                    this._privillageNum = this._privillageNum + 1;
                    break;
                }
                case "callTogether":
                {
                    if (this._callTogetherTxt == null) 
                    {
                        this._callTogetherTxt = ObjCreate.createGTextField("", this._btnX, this._btnY, 80, 20, this, GlobalStyle.textFormatGreen);
                        this._callTogetherTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(36442) + "</u></a>";
                        this._callTogetherTxt.addEventListener(flash.events.TextEvent.LINK, this.onCallTogetherTxtLinkHandler);
                        this._btnY = this._btnY + 25;
                    }
                    addChild(this._callTogetherTxt);
                    this._privillageNum = this._privillageNum + 1;
                    break;
                }
                case "countryBuff":
                {
                    if (this._countryBuffTxt == null) 
                    {
                        this._countryBuffTxt = ObjCreate.createGTextField("", this._btnX, this._btnY, 80, 20, this, GlobalStyle.textFormatGreen);
                        this._countryBuffTxt.htmlText = "<a href=\'event: 0\'><u>" + Language.getString(36443) + "</u></a>";
                        this._countryBuffTxt.addEventListener(flash.events.TextEvent.LINK, this.onCountryBuffTxtLinkHandler);
                        this._btnY = this._btnY + 25;
                    }
                    addChild(this._countryBuffTxt);
                    this._privillageNum = this._privillageNum + 1;
                    break;
                }
                case "countryTreasure":
                {
                    break;
                }
                case "startKill":
                {
                    break;
                }
            }
            this._panelBg.setSize(80, this._btnY + 5);
            return;
        }

        /* internal  */onResignTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=Language.getStringByParam(36444, this._posName);
            Alert.show(loc1, null, Alert.OK | Alert.CANCEL, null, this.onResignCloseHandler);
            return;
        }

        /* internal  */onResignCloseHandler(arg1: int): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (arg1 == Alert.OK) 
            {
                loc1 = ECountryPositionOperType.convert(ECountryPositionOperType._ECountryPositionOperTypeResign);
                loc2 = ECountryPosition.convert(ECountryPosition._ECountryPositionPeople);
                loc3 = {"fromPlayerId": 0, "toPlayerId": 0, "operType": loc1, "targetPosition": loc2};
                Dispatcher.dispatchEvent(new DataEvent(EventName.CountryOperPosition, loc3));
            }
            return;
        }

        /* internal  */onPositionOperTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (this._positionOperTxt.name != "appoint") 
            {
                if (this._positionOperTxt.name == "recall") 
                {
                    loc1 = this._playerName;
                    loc2 = this._posName;
                    loc3 = Language.getStringByParam(36445, loc1, loc2);
                    Alert.show(loc3, null, Alert.OK | Alert.CANCEL, null, this.onRecallCloseHandler);
                }
            }
            else 
            {
                this.updatePositionOperWindow();
            }
            return;
        }

        /* internal  */updatePositionOperWindow(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CountryAppointFriendPosition, {"position": _position, "posName": _posName}));
            return;
        }

        /* internal  */onRecallCloseHandler(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            if (arg1 == Alert.OK) 
            {
                loc1 = ECountryPositionOperType.convert(ECountryPositionOperType._ECountryPositionOperTypeRecall);
                if (this._officerInfo && this._officerInfo.player && this._officerInfo.player.entityId) 
                {
                    loc2 = this._officerInfo.player.entityId.id;
                }
                loc3 = ECountryPosition.convert(this._position);
                loc4 = {"fromPlayerId": 0, "toPlayerId": loc2, "operType": loc1, "targetPosition": loc3};
                Dispatcher.dispatchEvent(new DataEvent(EventName.CountryOperPosition, loc4));
            }
            return;
        }

        /* internal  */onCallTogetherTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CountryCallTogether));
            return;
        }

        /* internal  */onCountryBuffTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CountryOpenCountryBuff));
            return;
        }

        public removeOperBtn(): void
        {
            this._privillageNum = 0;
            if (this._positionOperTxt && this._positionOperTxt.parent) 
            {
                removeChild(this._positionOperTxt);
            }
            if (this._callTogetherTxt && this._callTogetherTxt.parent) 
            {
                removeChild(this._callTogetherTxt);
            }
            if (this._countryBuffTxt && this._countryBuffTxt.parent) 
            {
                removeChild(this._countryBuffTxt);
            }
            if (this._countryTreasureTxt && this._countryTreasureTxt.parent) 
            {
                removeChild(this._countryTreasureTxt);
            }
            if (this._startKillTxt && this._startKillTxt.parent) 
            {
                removeChild(this._startKillTxt);
            }
            if (this._resignTxt && this._resignTxt.parent) 
            {
                removeChild(this._resignTxt);
            }
            if (this._friendComBo && this._friendComBo.parent) 
            {
                removeChild(this._friendComBo);
            }
            return;
        }

        /* internal */ /* var */_panelBg: ScaleBitmap;

        /* internal */ /* var */_friendComBo: GComboBox;

        /* internal */ /* var */_positionOperTxt: GTextFiled;

        /* internal */ /* var */_callTogetherTxt: GTextFiled;

        /* internal */ /* var */_countryBuffTxt: GTextFiled;

        /* internal */ /* var */_countryTreasureTxt: GTextFiled;

        /* internal */ /* var */_startKillTxt: GTextFiled;

        /* internal */ /* var */_resignTxt: GTextFiled;

        /* internal */ /* var */_position: int;

        /* internal */ /* var */_officerInfo: SOfficerInfo;

        /* internal */ /* var */_playerName: string="";

        /* internal */ /* var */_posName: string="";

        /* internal */ /* var */_btnX: int=5;

        /* internal */ /* var */_btnY: int=5;

        /* internal */ /* var */_privillageNum: int=0;
    }
